var clickUtils = require("../../utils/clickUtils");
var randomUtils = require("../../utils/randomUtils");
var textUtils = require("../../utils/textUtils");
var ocrUtils = require("../../utils/ocrUtils");
var Action = require("../../base/Action");
var common = require("./common");
var pointMap = require("./pointMap");
var inTask = require("./inTask");
var aTreasure = new Action("宝箱", {});

aTreasure.goStartPage = function () {
  if (common.inHome()) {
    if (randomUtils.possible(0, 10)) {
      clickUtils.clickPointMap(pointMap.首页.视频);
      sleep(randomUtils.getRandom(10, 30, 1000));
    }
    if (randomUtils.possible(90, 100)) {
      clickUtils.clickPointMap(pointMap.首页.小说);
      sleep(randomUtils.getRandom(5, 10, 1000));
    }
    clickUtils.clickPointMap(pointMap.首页.任务);
    sleep(randomUtils.getRandom(5, 10, 1000));
    return true;
  }
};
aTreasure.exec = function () {
  inTask.init();
  sleep(randomUtils.getRandom(2, 3, 1000));
  var content = "开宝箱得金币";
  var TextUI = textUtils.existsTextStartsWith(content);
  if (TextUI) {
    clickUtils.clickTextUI(TextUI);
    sleep(randomUtils.getRandom(2, 3, 1000));
    inTask.init();
    return;
  }
  var content = "开宝箱得金币";
  var TextOCR = ocrUtils.captureExistsText(content);
  if (TextOCR) {
    clickUtils.clickTextOCR(TextOCR);
    sleep(randomUtils.getRandom(2, 3, 1000));
    inTask.init();
    return;
  }
  var content = "明天再来";
  var TextOCR = ocrUtils.captureExistsText(content);
  if (TextOCR) {
    this.todayIsOver = true;
  }
};

module.exports = aTreasure;
